import Api from '../../utils/api.js';

const app = getApp();

Page({
  data: {
    userType: '',
    currentSwiperItem: 0,
    projections: [] // 项目动态列表
  },
  async onLoad () {
    await app.appLogin();
    this.getProjections();
    this.setData({
      userType: app.globalData.userInfo.userType
    });
  },

  /* --====================数据接口====================-- */
  // 查询项目动态
  async getProjections () {
    const res = await Api.getProjections({
      sessionKey: app.globalData.sessionKey,
      currentPage: 1
    });
    if (res) {
      const projections = res.message.map(item => item.content.articles[0]);
      this.setData({ projections });
      app.globalData.projections = projections;
    }
  },

  /* --====================事件处理====================-- */
  // 用申请预约点击处理
  handleApplyTap (e) {
    const type = e.currentTarget.dataset.type;
    wx.navigateTo({
      url: `/pages/apply/apply?type=${type}`
    });
  },
  // 更多按钮点击处理
  handeMoreProjectNewTap () {
    wx.navigateTo({
      url: '/pages/projectNews/projectNews'
    });
  },
  // 其他留言按钮点击处理
  handleMessageTap () {
    wx.navigateTo({
      url: '/pages/message/message'
    });
  },
  // 项目动态点击处理
  handleProjectionTap (e) {
    app.toWebView(e.currentTarget.dataset.index);
  }
});
